<!DOCTYPE html>
<html>
<head>
	<#include "/pages/templet/head.html"/>
	<script type="text/javascript" src="/assets/js/jquery.hotkeys.min.js"></script> 				<!--页面按键事件-->
	<script type="text/javascript" src="/assets/js/R3_BigData.action.js"></script> 				<!--页面按键事件-->
	

	<script>
		var currentParityline = "%";
	    var selColDataID  = "";		//选中列的 ID

		var targetId = "";
		function zTreeOnDrop(event, treeId, treeNodes, targetNode, moveType) {
			var node = treeNodes[0];
			if(!node.isParent){
				if(targetId=="filter_div"){
					$("#filteradd_id").attr("href","/${orgi}/design/custom/${report.id!''}/<#if reportModel??>${reportModel.id!''}</#if>/filteradd/"+encodeURIComponent(node.name)+"/"+node.lid+".html");
					$("#filteradd_id").click();
				}else if(targetId=="measure_div"){
					//alert("添加指标");
				}
			}
		};

		var cubeNodeSetting = {
			edit: {
				enable: true,
				showRemoveBtn: false,
				showRenameBtn: false,
				drag: {
					prev: DargTree.prevTree,
					next: DargTree.nextTree,
					inner: DargTree.innerTree
				}
			},
			data: {
				keep: {
					parent: true,
					leaf: true
				},
				simpleData: {
					enable: true
				}
			},
			callback: {
				onDrop: DargTree.dropTree2Dom,
				onDragMove: DargTree.dragMove,
				onMouseUp: DargTree.dom2Tree,
				onRightClick: onRightClick,
				//onCollapse: alert("up"),
				onExpand: function(){
					if (treeNiceScroll) {
						treeNiceScroll.resize();
					}
				}
			},
			view: {
				showLine: false,
				nameIsHTML: true,
				showIcon: showIconForTree
			}
		};
		function onRightClick(event, treeId, treeNode) {
			cubeNodeZtree.selectNode(treeNode);
			var pid = treeNode.pId;
			if(pid == null || pid == "" || pid ==undefined){
				pid = "0";
			}
			if(pid !="0" && pid != "1"&& pid != "12"){
				if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
					cubeNodeZtree.cancelSelectedNode();
					showRMenu("root", event.clientX, event.clientY);
				} else if (treeNode && !treeNode.noR && treeNode.type =="dimensions") {
					cubeNodeZtree.selectNode(treeNode);
					showRMenu("node", event.clientX, event.clientY);
				} else{
					$("#rMenu_1 ul").show();
					$("#rMenu_1").css({"top":event.clientY+"px", "left":event.clientX+"px", "visibility":"visible"});
					$("body").bind("mousedown", onBodyMouseDown);
				}
			}
		}

		function showRMenu(type, x, y) {
			$("#rMenu ul").show();
			rMenu.css({"top":y+"px", "left":x+"px", "visibility":"visible"});

			$("body").bind("mousedown", onBodyMouseDown);
		}

		function hideRMenu() {
			if (rMenu) rMenu.css({"visibility": "hidden"});
			if (rMenu_1) rMenu_1.css({"visibility": "hidden"});
			$("body").unbind("mousedown", onBodyMouseDown);
		}
		function onBodyMouseDown(event){
			if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length>0)) {
				rMenu.css({"visibility" : "hidden"});
			}
			if (!(event.target.id == "rMenu_1" || $(event.target).parents("#rMenu_1").length>0)) {
				rMenu_1.css({"visibility" : "hidden"});
			}
		}
		function showIconForTree(treeId, treeNode) {
			return !(treeNode.type == 'measure');
		};
		function tableOperator(operator) {
			hideRMenu();
			var nodes = cubeNodeZtree.getSelectedNodes();
			if (nodes && nodes.length>0) {
				var name =  nodes[0].sname;
				var type = "measure";
				if(name=="" || name==null || name==undefined){
					name = nodes[0].name;
					type = "dimensions";
				}    
				if($("#"+nodes[0].lid).attr("data-check")=="false"){
					$("#"+nodes[0].lid).click();
					$("#"+nodes[0].lid).attr("data-check","true");
				}
				if(operator == "filter"){
					$("#filteradd_id").attr("href","/${orgi}/design/custom/filteradd/${report.id!''}/<#if reportModel??>${reportModel.id!''}</#if>/"+encodeURIComponent(name)+"/"+nodes[0].lid+".html");
					$("#filteradd_id").click();
				}else if (operator == "col"){
					ReportAction.syncReportModelMeasure(url_list.design_url+"?type="+type+"&oid="+nodes[0].lid+"&pos=right");
				}else if (operator == "row"){
					ReportAction.syncReportModelMeasure(url_list.design_url+"?type="+type+"&oid="+nodes[0].lid+"&pos=top");
				}else if (operator == "drill"){
					$("#drilldef").attr("href" , url_list.drilldef_url+"?title="+encodeURIComponent(name)+"&mid="+nodes[0].lid);
					$("#drilldef").click();
				}else if (operator == "remove"){
					if($("#"+nodes[0].lid).attr("data-check")=="true"){
						$("#"+nodes[0].lid).click();
					}
					ReportAction.syncReportModelMeasure(url_list.design_rmmeasure_url+"?type="+type+"&oid="+nodes[0].lid+"&pos=right");
				}
			} 			
		}

	
		var ReportURL = {
			newDomURL:"<#if reportModel??>/${orgi}/design/custom/modelinit/${report.id!''}/${reportModel.id!""}.html</#if>",
			designReportURL:"<#if reportModel??>/${orgi}/design/custom/designreport/${report.id!''}/${reportModel.id!""}.html</#if>"
			
		};
		var cubeNode = [
			<#if cube??>
			{ id:1, pId:0, name:"${cube.name!''}", open:true}
				<#list cube.dimension as dim>
					,{ id:${1000+dim_index}, pId:1, name:"${dim.name!''}" , open:false}
					<#if dim.cubeLevel??>
						<#list dim.cubeLevel as level>
							,{ id:${(1000+dim_index)*1000+level_index}, pId:${1000+dim_index}, type:"dimensions",lid:"${level.id!''}" , dimid:"${dim.id!''}", name:"${level.name!''}",icon:"/assets/images/dimensions.png"}
						</#list>
					</#if>
					<#if dim.dim?? && dim.dim.cubeLevel??>
						<#list dim.dim.cubeLevel as level>
							,{ id:${(1000+dim_index)*1000+level_index}, pId:${1000+dim_index}, type:"dimensions",lid:"${level.id!''}" , name:"${level.name!''}",icon:"/assets/images/dimensions.png"}
						</#list>
					</#if>
				</#list>
			
				<#if cube.measure?size gt 0>
				,{ id:12, pId:1, name:"指标", open:true}
				<#list cube.measure as measure>
				,{ id:${120000+measure_index}, pId:12, name:"<span style='display:inline-flex;'><input type='checkbox' <#if reportModel ?? && reportModel.measure ?? && reportModel.measure?index_of('${measure.id}') !=-1>checked='checked'</#if> value='${measure.id}' id='${measure.id}' name='measure' onclick='BtnAction.syncReportModelMeasure(this,\"${measure.id}\")' data-check='<#if reportModel ?? && reportModel.measure ?? && reportModel.measure?index_of('${measure.id}') !=-1>true<#else>false</#if>'> <span style='display:inline-flex;'>&nbsp;<i class='tabIcon tci-430' style='height:16px;margin-right:0px;'></i>${measure.name!''}</span></span>" , type:"measure" ,sname:"${measure.name!''}", lid:"${measure.id!''}",icon:""}
				</#list>
				</#if>
			</#if>
		];
	    
        var url_list = {
			design_url		: "<#if reportModel??>/${orgi}/design/custom/designreport/${report.id!''}/${reportModel.id!''}.html</#if>" ,
			design_rmmeasure_url	: "<#if reportModel??>/${orgi}/design/custom/rmmeasure/${report.id!''}/${reportModel.id!''}.html</#if>" ,
			save_url		: "<#if reportModel??>/${orgi}/design/custom/${report.id!''}/savereport.html</#if>" ,
			clear_url		: "<#if reportModel??>/${orgi}/design/custom/${report.id!''}/${reportModel.id!''}/cleareport.html</#if>",
			del_col_url		: "<#if reportModel??>/${orgi}/design/custom/${report.id!''}/${reportModel.id!''}/deletecol.html</#if>",
			merge_url		: "<#if reportModel??>/${orgi}/design/custom/merge/${report.id!''}/${reportModel.id!''}.html</#if>",
			clearmerge_url	: "<#if reportModel??>/${orgi}/design/custom/rmmerge/${report.id!''}/${reportModel.id!''}.html</#if>",
			cleardim_url	: "<#if reportModel??>/${orgi}/design/custom/rmdim/${report.id!''}/${reportModel.id!''}.html</#if>",
			rmnewcol_url	: "<#if reportModel??>/${orgi}/design/custom/rmnewcol/${report.id!''}/${reportModel.id!''}.html</#if>",
			rmnewrow_url	: "<#if reportModel??>/${orgi}/design/custom/rmnewrow/${report.id!''}/${reportModel.id!''}.html</#if>",
			newcol_url		: "<#if reportModel??>/${orgi}/design/custom/addsumcol/${report.id!''}/${reportModel.id!''}.html</#if>",
			newrow_url		: "<#if reportModel??>/${orgi}/design/custom/addsumrow/${report.id!''}/${reportModel.id!''}.html</#if>",
			exchange_url	: "<#if reportModel??>/${orgi}/design/custom/exchange/${report.id!''}/${reportModel.id!''}.html</#if>",
			exchange_viewtype	: "<#if reportModel??>/${orgi}/design/custom/exviewtype/${report.id!''}/${reportModel.id!''}.html</#if>",
			exchange_chartype	: "<#if reportModel??>/${orgi}/design/custom/exchartype/${report.id!''}/${reportModel.id!''}.html</#if>",
			style_url		: "<#if reportModel??>/${orgi}/design/custom/setstyle/${report.id!''}/${reportModel.id!''}.html</#if>",
			drilldef_url	: "<#if reportModel??>/${orgi}/design/custom/drilldef/${report.id!''}/${reportModel.id!''}.html</#if>",
			charts_url		: "<#if reportModel??>/${orgi}/design/custom/chart/${report.id!''}/${reportModel.id!''}.html</#if>",
			filteradd_url	: "<#if reportModel??>/${orgi}/design/custom/filteradd/${report.id!''}</#if>",
			clearzero_url	: "<#if reportModel??>/${orgi}/design/custom/clearzero/${report.id!''}/${reportModel.id!''}.html</#if>",
			filterparam_url	: "<#if reportModel??>/${orgi}/design/custom/filterparamadd/${report.id!''}/${reportModel.id!''}.html</#if>",
			warning_url		: "<#if reportModel??>/${orgi}/design/custom/warning/${report.id!''}/${reportModel.id!''}.html</#if>",
			editroworcol	: "<#if reportModel??>/${orgi}/design/custom/editsumcol/${report.id!''}/${reportModel.id!''}.html</#if>",
			filterquery_url : "/${orgi}/design/custom/${report.id!''}/<#if reportModel??>${reportModel.id!''}</#if>/queryFilter.html",
			viewquery_url	: "<#if reportModel??>/${orgi}/design/custom/viewQuery/${report.id!''}/${reportModel.id!''}.html</#if>"	,
			colpos_url		: "<#if reportModel??>/${orgi}/design/custom/colpos/${report.id!''}/${reportModel.id!''}.html</#if>"		
		} 
		var rMenu  , cubeNodeZtree ,rMenu_1;
	    $(document).ready(function(){
			
			KeyEvent.init();
	        cubeNodeZtree = $.fn.zTree.init($(document.getElementById("zTree_adminLIst")), cubeNodeSetting, cubeNode);
	       	rMenu = $("#rMenu");
	       	rMenu_1 = $("#rMenu_1");
        
	        $(".data_model p a").click(function(){
                if(!$(this).hasClass('active')){
                    $(this).siblings().removeClass('active');
                    $(this).addClass('active');
                }
	        });          
			$('.icon_xl span').click(function(event) {
                var curr_ol = $(this).next("ol");

                curr_ol.toggleClass("active");
                $(".selectauto").css({
                    'marginLeft': '-9999px'
                });
                $(document).bind("click", function() { //对document绑定一个隐藏Div方法 
					event.stopPropagation();//点击Button阻止事件冒泡到document
                    curr_ol.removeClass('active');
                });
				event.stopPropagation();//点击Button阻止事件冒泡到document
            });

            $(".icon_xl ol li,.font_div a").click(function(event) {	               
				event.stopPropagation();//点击Button阻止事件冒泡到document 
                //event.stopPropagation();//在Div区域内的点击事件阻止冒泡到document 
            });
			$("#fontcolor").colorpicker({
				fillcolor:true,
	    		target:$("#fontcolor"),
	    		success:function(o,color){
	    			BtnAction.setstyle('color', color , '<#if reportModel??>${reportModel.id}</#if>')
	    		},
				reset:function(){
					BtnAction.setstyle('color', "" , '<#if reportModel??>${reportModel.id}</#if>')
				}
			});
			
			$("#bgcolor").colorpicker({
				fillcolor:true,
	    		target:$("#bgcolor"),
	    		success:function(o,color){
	    			BtnAction.setstyle('backgroundcolor', color , '<#if reportModel??>${reportModel.id}</#if>')
	    		},
				reset:function(){
					BtnAction.setstyle('backgroundcolor', "" , '<#if reportModel??>${reportModel.id}</#if>')
				}
			});
			$('#colorpanel table').css("border","0px");
			$('#DisColor').css("height","10px");
			$('#HexColor').css("height","10px");

	    });
		window.onload=window.onresize=function(){
			  resizeDesign();
		}
		function resizeDesign(){
			var winHeight = $(window).height() , winWidth = $(window).width();
			var isNotIE=-[-1,];
			if(isNotIE)
			{
				 scrollHeight = document.body.scrollHeight;//非IE浏览器
			}
			else
			{
				 scrollHeight = document.documentElement.scrollHeight;//IE浏览器
			}
			<#if !reportModel?? || (reportModel.viewtype?? && reportModel.viewtype == "view")>
			$('#data_table').height(winHeight-70 - $('.shrinkage').height());
			<#else>
			$('#chart_table').height(winHeight-130 - $('.shrinkage').height());
			</#if>
		}
		function submitSearchForm(action){
			//$("#beginNum").val($("#beginNumShow").val());
			//$("#endNum").val($("#endNumShow").val());
			var reg = /^[0-9]*$/;
			if(reg.test($("#p").val())){
				loadURL(url_list.filterquery_url+"?p="+$("#p").val()+"&ps="+$("#ps").val()+"&opt="+action , "#design_table");
			}else{
				alertMsg("请输入正确的页码信息！");
			}
		}
	</script>
	<style type="text/css">
		div#rMenu {position:absolute; visibility:hidden; top:0; background-color: #FFF;text-align: left;z-index:10000;border: 1px solid #09f;border-bottom:0px;}
		div#rMenu ul li{
			margin: 0px 0;
			padding: 5px 5px 5px 5px;				
			cursor: pointer;
			font-size:12px;
			width:100px;
			list-style: none outside none;
			border-bottom: 1px solid #cccccc;
		}
		div#rMenu_1 ul li:hover{
			background-color:#EFEFEF;
		}
		div#rMenu_1 {position:absolute; visibility:hidden; top:0; background-color: #FFF;text-align: left;z-index:10000;border: 1px solid #09f;border-bottom:0px;}
		div#rMenu_1 ul li{
			margin: 0px 0;
			padding: 5px 5px 5px 5px;				
			cursor: pointer;
			font-size:12px;
			width:100px;
			list-style: none outside none;
			border-bottom: 1px solid #cccccc;
		}
		div#rMenu_1 ul li:hover{
			background-color:#EFEFEF;
		}
		
	</style>
</head>
<a href="javascript:void(0)" data-toggle="ajax" data-width="600" class="tbtn" hidden="" id = "drilldef"></a>
<body>
    <div class="container rs_layout" wrapper="true">
        <!-- Everything started here -->
        <div class="rs_layout_top">
            <div class="nav_top" style="background-color:#FFFFFF;color:#000000;">
                <!--NavTop-->
                <h1 class="comName" style="color:#333333;">
                    ${report.name!''}
                </h1>
				<div class="nav_controlBar">
					<ul class="nav_controlList">
						<li class="nav_control_data_view nav_control_cur"><a href="/rivues/user/index.html" title="切换到透视视图"><img src="/assets/images/toushiview.png" width="24"></a></li>
						<li class="nav_control_data_view"><a href="/${orgi}/design/custom/selcube/${report.id!''}.html<#if reportModel??>?modelid=${reportModel.id!''}</#if>"  data-toggle="ajax"  title="选择数据或上传数据文件"><img src="/assets/images/dataview.png" width="24"></a></li>
					</ul>
				</div>
            </div>             
        </div>
        <div class="rs_layout_center reTabcon" style="border-top:solid 2px #d8af84;">
            <div class="rs_layout rTablayer show">
				<#if cube??>
                <div class="rs_layout_left" resizable="true" minsize="true" style="width:230px;">
                    <div class="rs_layout">
						<div class="rs_layout_center">
                            <div class="lftTreeWrap lf_ct">
                                <div class="ztree" id="zTree_adminLIst">
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--<div class="rs_layout_right" style="width:300px;"></div>-->
                <div class="rs_layout_center">
                    <div class="rs_layout">
						<div id="design_table" >
							<#include "datadiv.html"/> 							
						 </div>							 
                    </div>
                </div>
				<#else>
				<!-- 未定义数据源 的 操作向导显示界面 -->
				<div class="rs_layout_center">
                    <div class="rs_layout">
						<div class="custom_builder">
							<p class="custom_builder_title custom_builder_title_active"><span>1</span><a href="/${orgi}/design/custom/selcube/${report.id!''}.html<#if reportModel??>?modelid=${reportModel.id!''}</#if>"  data-toggle="ajax"  title="选择数据或上传数据文件">选择、上传</a></p>
							<p class="custom_builder_line"></p>
							<p class="custom_builder_title"><span>2</span>拖拽</p>
							<p class="custom_builder_line"></p>
							<p class="custom_builder_title"><span>3</span>发布</p>
						</div>						 
                    </div>
                </div>
				</#if>
            </div>
        </div>
    </div>
	<div id="rMenu">
		<ul>
			<li id="m_add" onclick="tableOperator('filter');"><span><img src="/assets/images/top_icon124.png"/></span><span style="margin-left:10px;">添加过滤器</span></li>
			<li id="m_del" onclick="tableOperator('col');"><span><img src="/assets/images/ctr-icons-119.png"></span><span style="margin-left:10px;">添加到列</span></li>
			<li id="m_check" onclick="tableOperator('row');"><span><img src="/assets/images/ctr-icons-120.png"></span><span style="margin-left:10px;">添加到行</span></li>
			<!--<li id="m_unCheck" onclick="tableOperator('drill');"><span><img src="/assets/images/top_icon123.png"></span><span style="margin-left:10px;">插入钻取</span></li>-->
			<li id="m_reset" onclick="tableOperator('remove');" style="border-bottom:1px solid #09f;"><span><img src="/assets/images/ctr-icons-115.png"></span><span style="margin-left:10px;">从表格中移除</span></li>
		</ul>
	</div>
	<div id="rMenu_1">
		<ul>
			<li id="m_add" onclick="tableOperator('filter');"><span><img src="/assets/images/top_icon124.png"/></span><span style="margin-left:10px;">添加过滤器</span></li>
			<li id="m_del" onclick="tableOperator('col');"><span><img src="/assets/images/ctr-icons-119.png"></span><span style="margin-left:10px;">添加到列</span></li>
			<li id="m_unCheck" onclick="tableOperator('drill');"><span><img src="/assets/images/top_icon123.png"></span><span style="margin-left:10px;">插入钻取</span></li>
			<li id="m_reset" onclick="tableOperator('remove');" style="border-bottom:1px solid #09f;"><span><img src="/assets/images/ctr-icons-115.png"></span><span style="margin-left:10px;">从表格中移除</span></li>
		</ul>
	</div>

<!--[if gte IE 8]>
<script type="text/javascript">
	$(".shtitle").each(function(i) {
		var ls = $('.lx'+(i+1)+' li').width();
		$('.lx'+(i+1)+' em').css({'width': ls + 'px'});
	});
</script>
 <![endif]-->
 <!--[if !IE]><!--> 
<script type="text/javascript">
	$(function() {
		$(".shtitle").each(function(i) {
			var ls = $('.lx' + (i + 1) + ' li').width();
			$('.lx' + (i + 1) + ' em').css({
				'width': ls + 'px'
			});
			$(this).css("z-index","1000");
		});
	});
</script>
 <!--<![endif]-->
</body>
</html>